{% import "components/user.html" as user with context %}
{% import "components/contest.html" as contest with context %}
<div class="section side">
{% if page_name != 'contest_detail' %}
  <a class="contest-sidebar__bg" href="{{ reverse_url('contest_detail', tid=tdoc['doc_id']) }}">
    <div class="section__body">
      <h1>{{ tdoc['title'] }}</h1>
      <div class="contest-sidebar__status">
      {% if attended %}
        <span class="icon icon-check"></span> {{ _('Attended') }}
      {% else %}
        <span class="icon icon-schedule"></span> {{ _('Not Attended') }}
      {% endif %}
      </div>
    </div>
  </a>
{% endif %}
  <div>
    <ol class="menu">
    {% if page_name == 'discussion_node' %}
    {% if handler.has_perm(vj4.model.builtin.PERM_CREATE_DISCUSSION) %}
      <li class="menu__item"><a class="menu__link highlight" href="{{ reverse_url('discussion_create_document_as_node', doc_type=tdoc['doc_type'], doc_id=tdoc['doc_id']) }}">
        <span class="icon icon-add"></span> {{ _('Create a Discussion') }}
      </a></li>
    {% else %}
      {% if not handler.has_priv(vj4.model.builtin.PRIV_USER_PROFILE) %}
        <li class="menu__item"><a class="menu__link" href="javascript:showSignInDialog();">
        <span class="icon icon-add"></span> {{ _('Login to Create a Discussion') }}</a></li>
      {% else %}
        <li class="menu__item"><a class="menu__link disabled" href="javascript:;">
        <span class="icon icon-add"></span> {{ _('No Permission to Create a Discussion') }}</a></li>
      {% endif %}
    {% endif %}
      <li class="menu__seperator"></li>
    {% endif %}
    {% if page_name != 'contest_detail' %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('contest_detail', tid=tdoc['doc_id']) }}">
        <span class="icon icon-award"></span> {{ _('View Contest') }}
      </a></li>
    {% endif %}
    {% if not attended and not handler.is_done(tdoc) %}
      <li class="menu__item">
    {% if handler.has_perm(vj4.model.builtin.PERM_ATTEND_CONTEST) and handler.has_priv(vj4.model.builtin.PRIV_USER_PROFILE) %}
        <form action="{{ reverse_url('contest_detail', tid=tdoc['doc_id']) }}" method="POST">
          <input type="hidden" name="operation" value="attend">
          <input type="hidden" name="csrf_token" value="{{ handler.csrf_token }}">
          <button class="menu__link" type="submit">
            <span class="icon icon-add"></span> {{ _('Attend Contest') }}
          </button>
        </form>
    {% elif not handler.has_priv(vj4.model.builtin.PRIV_USER_PROFILE) %}
        <a class="menu__link" href="javascript:showSignInDialog()">
          <span class="icon icon-add"></span> {{ _('Login to Attend Contest') }}
        </a>
    {% else %}
        <a class="menu__link disabled" href="javascript:;">
          <span class="icon icon-add"></span> {{ _('No Permission to Attend Contest') }}
        </a>
    {% endif %}
      </li>
    {% endif %}
    {% if handler.can_show_scoreboard(tdoc, False) %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('contest_scoreboard', tid=tdoc['doc_id']) }}">
        <span class="icon icon-statistics"></span> {{ _('Scoreboard') }}
      </a></li>
    {% elif handler.can_view_hidden_scoreboard(tdoc) %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('contest_scoreboard', tid=tdoc['doc_id']) }}">
        <span class="icon icon-statistics"></span> {{ _('Scoreboard (Hidden)') }}
      </a></li>
    {% endif %}
    {% if handler.own(tdoc, vj4.model.builtin.PERM_EDIT_CONTEST_SELF) or handler.has_perm(vj4.model.builtin.PERM_EDIT_CONTEST) %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('contest_edit', tid=tdoc['doc_id']) }}">
        <span class="icon icon-edit"></span>  {{ _('Edit') }}
      </a></li>
    {% endif %}
    {% if handler.has_perm(vj4.model.builtin.PERM_READ_RECORD_CODE) %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('contest_code', tid=tdoc['doc_id']) }}">
        <span class="icon icon-download"></span> {{ _('Export All Code') }}
      </a></li>
    {% endif %}
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('record_main') }}?tid={{ tdoc['doc_id'] }}">
        <span class="icon icon-flag"></span> {{ _('All Submissions') }}
      </a></li>
      <li class="menu__item"><a class="menu__link" href="{{ reverse_url('wiki_help') }}#contest">
        <span class="icon icon-help"></span> {{ _('Help') }}
      </a></li>
      <li class="menu__seperator"></li>
    </ol>
  </div>
  <div class="section__body typo">
    <dl class="large horizontal">
      <dt>{{ _('Status') }}</dt><dd>{{ _(handler.status_text(tdoc)) }}</dd>
      <dt>{{ _('Rule') }}</dt><dd>{{ vj4.constant.contest.RULE_TEXTS[tdoc['rule']] }}</dd>
      <dt>{{ _('Problem') }}</dt><dd>{{ tdoc['pids']|length }}</dd>
      <dt>{{ _('Start at') }}</dt><dd>{{ contest.render_time(tdoc['begin_at']) }}</dd>
      <dt>{{ _('End at') }}</dt><dd>{{ contest.render_time(tdoc['end_at']) }}</dd>
      <dt>{{ _('Duration') }}</dt><dd>{{ contest.render_duration(tdoc) }} {{ _('hour(s)') }}</dd>
      <dt>{{ _('Host') }}</dt><dd>{{ user.render_inline(owner_udoc, badge=false) }}</dd>
      <dt>{{ _('Partic.') }}</dt>
      <dd>
        {{ tdoc['attend']|default(0) }}
      {% if attended %}
        ({{ _('Attended') }})
      {% endif %}
      </dd>
    </dl>
  </div>
</div>
